package cq.com.cn.dao;

import cq.com.cn.model.UserModel;
import cq.com.cn.utils.JDBCUtils;
import org.apache.commons.lang3.StringUtils;

public class UserDao {

    private static final String FINDUSERBYEMAIL="select * from user where email=?";
    private static final String INSERTTUSER="INSERT INTO USER(email,loginName,niceName,pwd,gender,phone,remark,lastLoginTime,account) values(?,?,?,?,?,?,?,now(),1000)";
    private static final String USERLOGIN = "select * from user where loginName=? and pwd=?";

    public UserModel queryUserByEmail(String email) {
        return JDBCUtils.findOne(UserModel.class,FINDUSERBYEMAIL,email);
    }
    public void insertUser(UserModel user) {
        if(StringUtils.isNotBlank(user.getRemark())){
            user.setRemark(user.getRemark().trim());
        }
        Object  [] objArray=new Object[]{user.getEmail(),user.getLoginName(),user.getNiceName(),user.getPwd(),user.getGender(),user.getPhone(),user.getRemark()};
        JDBCUtils.operater(INSERTTUSER,objArray);
    }

    public UserModel findUser(String longinName,String pwd){
       return JDBCUtils.findOne(UserModel.class,USERLOGIN,new Object[]{longinName,pwd});
    }
}
